package com.momo.web.controller.sysSetting;

import com.momo.common.common.JSONResult;
import com.momo.common.req.sysSetting.dept.SaveDeptReq;
import com.momo.service.sysSetting.SysDeptService;
import com.momo.service.sysSetting.SysDeptTreeService;
import com.momo.web.controller.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;

/**
 * Created by MOMO on 2019/2/18.
 */
@RestController
@RequestMapping(value = "/platform/dept", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
@Slf4j
public class SysDeptController extends BaseController {
    @Autowired
    private SysDeptTreeService sysDeptTree;
    @Autowired
    private SysDeptService sysDeptService;

    /**
     * 部门树
     *
     * @return
     */
    @PostMapping("/depteTree/v1")
    public JSONResult depteTree() {
        return JSONResult.ok(sysDeptTree.deptTree(this.redisUser()));
    }

    /**
     * 新增部门
     *
     * @param saveDeptReq
     * @return
     */
    @PostMapping("/save/v1")
    public JSONResult save(@Validated(SaveDeptReq.save.class) @RequestBody SaveDeptReq saveDeptReq) {
        return sysDeptService.save(saveDeptReq, this.redisUser());
    }

    /**
     * 编辑部门
     *
     * @param saveDeptReq
     * @return
     */
    @PostMapping("/update/v1")
    public JSONResult update(@Validated(SaveDeptReq.Modify.class) @RequestBody SaveDeptReq saveDeptReq) {
        return sysDeptService.update(saveDeptReq, this.redisUser());
    }

    /**
     * 查看部门详情
     *
     * @param saveDeptReq
     * @return
     */
    @PostMapping("/detail/v1")
    public JSONResult detail(@Validated(SaveDeptReq.Detail.class) @RequestBody SaveDeptReq saveDeptReq) {
        return sysDeptService.detail(saveDeptReq);
    }
}
